package ynu.edu;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import ynu.edu.entity.User;
import ynu.edu.feign.ProviderFeignClient;

@SpringBootApplication
public class ConsumerApplication implements CommandLineRunner {

    @Autowired
    private ProviderFeignClient providerFeignClient;

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 远程调用获取用户信息
        Long userId = 1L; // 假设用户ID为1
        User user = providerFeignClient.getUser(userId);
        System.out.println("获取到的用户信息：" + user);

        // 创建用户
        User newUser = new User();
        newUser.setName("张三");
        newUser.setAge(25);
        User createdUser = providerFeignClient.createUser(newUser);
        System.out.println("创建的用户信息：" + createdUser);

        // 更新用户信息
        newUser.setAge(30);
        User updatedUser = providerFeignClient.updateUser(userId, newUser);
        System.out.println("更新后的用户信息：" + updatedUser);

        // 删除用户
        providerFeignClient.deleteUser(userId);
        System.out.println("用户删除成功");
    }
}
